package org.example.MyExecption;

import org.example.myEnum.ErrorCode;

/**
 * 自定义业务异常
 */
public class BusinessException extends RuntimeException {
    // 错误码
    private final int code;
    // 错误详情（可选）
    private final String detail;

    // 基础构造器
    public BusinessException(int code, String message) {
        super(message);
        this.code = code;
        this.detail = "";
    }

    // 带详情的构造器
    public BusinessException(int code, String message, String detail) {
        super(message);
        this.code = code;
        this.detail = detail;
    }

    // 使用预定义错误码（推荐）
    public BusinessException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.detail = "";
    }

    // Getters
    public int getCode() {
        return code;
    }
    public String getDetail() {
        return detail;
    }
}